//
//  MyTabBarController.m
//  PeopleStreet
//
//  Created by 刘建峰 on 2016/11/29.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "MyTabBarController.h"
#import "MyNavigationViewController.h"

@interface MyTabBarController ()

@end

@implementation MyTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self greatChildControllers];
    [self configurationNavigationAndTabbar];
    // Do any additional setup after loading the view.
}

- (void)greatChildControllers{
    //b.创建子控制器
    UIStoryboard *oneStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page1 = [oneStroyBoard instantiateViewControllerWithIdentifier:@"Home"];
    MyNavigationViewController * nav1 = [[MyNavigationViewController alloc]initWithRootViewController:page1];
    nav1.navigationBarHidden = YES;
    
    
    UIStoryboard *twoStroyBoard=[UIStoryboard storyboardWithName:@"AttractStoryboard" bundle:nil];
    UIViewController *page2 = [twoStroyBoard instantiateViewControllerWithIdentifier:@"Attract"];
    MyNavigationViewController * nav2 = [[MyNavigationViewController alloc]initWithRootViewController:page2];
    nav2.navigationBarHidden = YES;
    
    
    
    UIStoryboard *fourStroyBoard=[UIStoryboard storyboardWithName:@"MyCodeStoryboard" bundle:nil];
    UIViewController *page4 = [fourStroyBoard instantiateViewControllerWithIdentifier:@"MyCode"];
    
    MyNavigationViewController * nav4 = [[MyNavigationViewController alloc]initWithRootViewController:page4];
    nav4.navigationBarHidden = YES;
    
    
    UIStoryboard *fiveStroyBoard=[UIStoryboard storyboardWithName:@"VIPServiceStoryboard" bundle:nil];
    UIViewController *page5 = [fiveStroyBoard instantiateViewControllerWithIdentifier:@"VipServiceNew"];
    
    MyNavigationViewController * nav5 = [[MyNavigationViewController alloc]initWithRootViewController:page5];
    nav5.navigationBarHidden = YES;
    
    UIStoryboard *sixStroyBoard=[UIStoryboard storyboardWithName:@"PersonCenterStoryboard" bundle:nil];
    UIViewController *page6 = [sixStroyBoard instantiateViewControllerWithIdentifier:@"PersonCenter"];
    
    MyNavigationViewController * nav6 = [[MyNavigationViewController alloc]initWithRootViewController:page6];
    nav6.navigationBarHidden = YES;
    
    self.viewControllers=@[nav1,nav2,nav4,nav5,nav6];

}

//配置导航栏与状态栏
- (void)configurationNavigationAndTabbar{
    //为工具栏设置标题与图片
    UITabBar *tabBar = self.tabBar;
    tabBar.tintColor = [UIColor clearColor];
    tabBar.selectedImageTintColor = [UIColor clearColor];
    tabBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nav_bg.jpg"]];
    UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
    UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
    UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
    UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
    UITabBarItem *tabBarItem5 = [tabBar.items objectAtIndex:4];
    //声明这张图片用原图(别渲染)
    UIColor *selectColor = [UIColor colorWithRed:0.957 green:0.616 blue:0.102 alpha:1.000];
    UIColor *normalColor = [UIColor colorWithWhite:0.200 alpha:1.000];
    UIImage *selectedImage = [UIImage imageNamed:@"home_yes.png"];
    selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem1.title = @"首页";
    [tabBarItem1 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:[UIImage imageNamed:@"home_no.png"]];
    [tabBarItem1 setTitleTextAttributes:[NSDictionary dictionaryWithObject:selectColor forKey:NSForegroundColorAttributeName] forState:UIControlStateSelected];
    [tabBarItem1 setTitleTextAttributes:[NSDictionary dictionaryWithObject:normalColor forKey:NSForegroundColorAttributeName] forState:UIControlStateNormal];
    
    UIImage *selectedImage2 = [UIImage imageNamed:@"nav2.png"];
    selectedImage2 = [selectedImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem2.title = @"招商入驻";
    [tabBarItem2 setFinishedSelectedImage:[[UIImage imageNamed:@"nav2_on"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] withFinishedUnselectedImage:selectedImage2];
    [tabBarItem2 setTitleTextAttributes:[NSDictionary dictionaryWithObject:selectColor forKey:NSForegroundColorAttributeName] forState:UIControlStateSelected];
    [tabBarItem2 setTitleTextAttributes:[NSDictionary dictionaryWithObject:normalColor forKey:NSForegroundColorAttributeName] forState:UIControlStateNormal];
    
    UIImage *selectedImage3 = [UIImage imageNamed:@"nav3.png"];
    selectedImage3 = [selectedImage3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem3.title = @"积分商城";
    
    [tabBarItem3 setFinishedSelectedImage:[[UIImage imageNamed:@"nav3_on.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] withFinishedUnselectedImage:selectedImage3];
    [tabBarItem3 setTitleTextAttributes:[NSDictionary dictionaryWithObject:selectColor forKey:NSForegroundColorAttributeName] forState:UIControlStateSelected];
    [tabBarItem3 setTitleTextAttributes:[NSDictionary dictionaryWithObject:normalColor forKey:NSForegroundColorAttributeName] forState:UIControlStateNormal];
    
    UIImage *selectedImage4 = [UIImage imageNamed:@"nav4.png"];
    selectedImage4 = [selectedImage4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem4.title = @"会员服务";
    
    [tabBarItem4 setFinishedSelectedImage:[[UIImage imageNamed:@"nav4_on.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] withFinishedUnselectedImage:selectedImage4];
    [tabBarItem4 setTitleTextAttributes:[NSDictionary dictionaryWithObject:selectColor forKey:NSForegroundColorAttributeName] forState:UIControlStateSelected];
    [tabBarItem4 setTitleTextAttributes:[NSDictionary dictionaryWithObject:normalColor forKey:NSForegroundColorAttributeName] forState:UIControlStateNormal];
    
    UIImage *selectedImage5 = [UIImage imageNamed:@"nav5.png"];
    selectedImage5 = [selectedImage5 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem5.title = @"我的";
    
    [tabBarItem5 setFinishedSelectedImage:[[UIImage imageNamed:@"nav5_on.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] withFinishedUnselectedImage:selectedImage5];
    [tabBarItem5 setTitleTextAttributes:[NSDictionary dictionaryWithObject:selectColor forKey:NSForegroundColorAttributeName] forState:UIControlStateSelected];
    [tabBarItem5 setTitleTextAttributes:[NSDictionary dictionaryWithObject:normalColor forKey:NSForegroundColorAttributeName] forState:UIControlStateNormal];
    
    
}



// 是否支持转屏
- (BOOL)shouldAutorotate
{
    return [self.selectedViewController shouldAutorotate];
}
// 返回nav栈中的最后一个对象支持的旋转方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return [self.selectedViewController supportedInterfaceOrientations];
}
// 返回nav栈中最后一个对象,坚持旋转的方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
